package top.fengleifeng.question;

import java.util.LinkedList;
import java.util.List;
import top.fengleifeng.util.Constants;

/**
 * @author : fengleifeng
 * @Package top.fengleifeng.question
 * @Description:
 * @date Date : 2021年01月05日 8:36 下午
 */
public class Num830较大分组的位置 {

    class Solution {

        public List<List<Integer>> largeGroupPositions(String s) {
            List<List<Integer>> result = new LinkedList<>();
            if (s.length() < 3) {
                return result;
            }
            char[] chars = s.toCharArray();
            char before = chars[0];
            int startSize = 0;
            for (int i = 1; i < s.length(); i++) {
                char c = chars[i];
                if (c == before) {
                    
                } else {
                    int equalNum = i - startSize - 1;
                    if (equalNum >= 2) {
                        List<Integer> list = new LinkedList<>();
                        list.add(startSize);
                        list.add(i - 1);
                        result.add(list);
                    }
                    before = c;
                    startSize = i;
                }
            }
            int equalNum = s.length() - 1 - startSize ;
            if (equalNum >= 2) {
                List<Integer> list = new LinkedList<>();
                list.add(startSize);
                list.add(s.length() - 1);
                result.add(list);
            }
            return result;
        }
    }

    public static void main(String[] args) {
//        String s = "abbxxxxzzy";
//        String s = "abc";
//        String s = "abcdddeeeeaabbbcd";
        String s = "aaa";
        List<List<Integer>> lists = new Num830较大分组的位置().new Solution().largeGroupPositions(s);
        Constants.pringtLinkedList(lists);
    }
}
